<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">

    <body>

        <ui:composition template="./../Template.xhtml">



            <ui:define name="content">
                <h:form id="form">
                    <p:growl id="messages"/>
                    <h:panelGrid columns="2">
                        <f:facet name="header">
                            Edição dos Professores Cadastrados
                        </f:facet>
                        <h:outputText value="Escola.:"/>
                        <p:selectOneMenu value="#{professorFaces.selectedEscola}" converter="EscolaConverter">
                            <f:selectItem itemLabel="Selecione" itemValue="#{null}"/>
                            <f:selectItems value="#{escolaFaces.allEscolas}" var="escola" itemLabel="#{escola.escola}" itemValue="#{escola}"/>
                        </p:selectOneMenu>


                    </h:panelGrid>

                    <p:commandButton value="Filtrar" action="#{professorFaces.preencheProfessorPorEscola()}" update="profList"/>
                    <br/>
                    <br/>
                    <p:dataTable  var="prof" value="#{professorFaces.professores}" id="profList" editable="true">
                        <f:facet name="header">
                            Edição dos Professores
                        </f:facet>
                        <p:ajax event="rowEdit" listener="#{professorFaces.onEdit(event)}" update=":form:messages" />
                        <p:ajax event="rowEditCancel" listener="#{professorFaces.onCancel(event)}" update=":form:messages" />

                         <p:column headerText="Escola" style="width:30%">
                            <p:cellEditor>
                                <f:facet name="output">
                                    <h:outputText value="#{prof.escola.escola}" />
                                </f:facet>
                                <f:facet name="input">
                                    <h:selectOneMenu value="#{prof.escola}"  converter="EscolaConverter">  
                                        <f:selectItems value="#{escolaFaces.allEscolas}"  
                                                       var="esc"   
                                                       itemLabel="#{esc.escola}"  
                                                       itemValue="#{esc}" />  
                                    </h:selectOneMenu>  
                                </f:facet>
                            </p:cellEditor>

                        </p:column>
                        <p:column headerText="Nome" style="width:30%">
                            <p:cellEditor>
                                <f:facet name="output">
                                    <h:outputText value="#{prof.nome}" />
                                </f:facet>
                                <f:facet name="input">
                                    <p:inputText value="#{prof.nome}" style="width:100%"/>
                                </f:facet>
                            </p:cellEditor>
                        </p:column>
                        <p:column headerText="CPF" style="width:30%">
                            <p:cellEditor>
                                <f:facet name="output">
                                    <h:outputText value="#{prof.cpf}" />
                                </f:facet>
                                <f:facet name="input">
                                    <p:inputText value="#{prof.cpf}" style="width:100%"/>
                                </f:facet>
                            </p:cellEditor>
                        </p:column>
                       
                        <p:column style="width:40%">
                            <f:facet name="output">
                                <h:outputText value="Editar - Apagar" />
                            </f:facet>
                            <p:commandButton  action="#{professorFaces.startEditProfessor()}"  ajax="false"  icon="ui-icon-pencil" alt="Editar Informações" label="Editar">
                                <f:setPropertyActionListener target="#{professorFaces.selectedProfessor}" value="#{prof}"/>
                            </p:commandButton>
                            <p:commandButton   action="#{professorFaces.delProfessor()}"  ajax="false" update="form:profList" icon="ui-icon-trash" alt="Apagar Informações" label="Apagar">
                                <f:setPropertyActionListener target="#{professorFaces.selectedProfessor}" value="#{prof}"/>
                            </p:commandButton>
                        </p:column>
                    </p:dataTable>


                </h:form>
            </ui:define>



        </ui:composition>

    </body>
</html>
